import { RouteRecordRaw } from 'vue-router';
import Layouts from '~/layouts/index.vue';

// 默认导航的页面
const defaultHomePagePath = '/user/my-data';

const loginPagePath = '/login';

const notFoundPagePath = '/result/404';

// 404组件
const NOT_FOUND_PAGE = () => import('~/pages/result/notFound.vue');

const LOGIN_PAGE = () => import('~/pages/login/index.vue');

/**
 * 路由具有唯一性，动态路由与静态路由name不能重复，
 * 否则动态路由配置会替换静态路由配置
 */
const routes: Array<RouteRecordRaw> = [
  {
    path: '/result',
    name: 'result',
    meta: { title: '结果页', icon: 'check-circle' },
    children: [
      {
        path: 'success',
        name: 'resultSuccess',
        component: () => import('~/pages/result/index.vue'),
        meta: { title: '成功页' }
      },
      {
        path: '404',
        name: 'notFound',
        component: NOT_FOUND_PAGE,
        meta: { title: '404' }
      }
    ]
  },
  {
    path: '/user',
    component: Layouts,
    children: [
      {
        path: 'my-data',
        name: '我的数据',
        component: () => import('~/pages/user/myData.vue')
      }
    ]
  },
  {
    path: '/',
    redirect: defaultHomePagePath
  },
  {
    path: '/login',
    name: 'login',
    component: LOGIN_PAGE
  },
  {
    path: '/:w+',
    name: '404',
    redirect: notFoundPagePath
  }
];

export default routes;

export { defaultHomePagePath, loginPagePath };
